
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/21/2012 21:54:45
-- Generated from EDMX file: C:\valdevirval-s2b\Repositorio\Help Us\Help Us\Model\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [HelpUs];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_premiopagamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[pagamentoSet] DROP CONSTRAINT [FK_premiopagamento];
GO
IF OBJECT_ID(N'[dbo].[FK_problemapremio]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[premioSets] DROP CONSTRAINT [FK_problemapremio];
GO
IF OBJECT_ID(N'[dbo].[FK_resolProblemapagamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[pagamentoSet] DROP CONSTRAINT [FK_resolProblemapagamento];
GO
IF OBJECT_ID(N'[dbo].[FK_usuOrganizacaoendereco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[enderecoSets] DROP CONSTRAINT [FK_usuOrganizacaoendereco];
GO
IF OBJECT_ID(N'[dbo].[FK_usuOrganizacaopagamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[pagamentoSet] DROP CONSTRAINT [FK_usuOrganizacaopagamento];
GO
IF OBJECT_ID(N'[dbo].[FK_usuOrganizacaoproblema]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[premioSet_problemas] DROP CONSTRAINT [FK_usuOrganizacaoproblema];
GO
IF OBJECT_ID(N'[dbo].[FK_usuResolvedorSetspagamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[pagamentoSet] DROP CONSTRAINT [FK_usuResolvedorSetspagamento];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[enderecoSet_usuOrganizacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[enderecoSet_usuOrganizacao];
GO
IF OBJECT_ID(N'[dbo].[enderecoSets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[enderecoSets];
GO
IF OBJECT_ID(N'[dbo].[pagamentoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[pagamentoSet];
GO
IF OBJECT_ID(N'[dbo].[premioSet_problemas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[premioSet_problemas];
GO
IF OBJECT_ID(N'[dbo].[premioSets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[premioSets];
GO
IF OBJECT_ID(N'[dbo].[resolProblemaSets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[resolProblemaSets];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO
IF OBJECT_ID(N'[dbo].[usuAdminsitradorSets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[usuAdminsitradorSets];
GO
IF OBJECT_ID(N'[dbo].[usuResolvedorSets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[usuResolvedorSets];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'enderecoSet_usuOrganizacao'
CREATE TABLE [dbo].[enderecoSet_usuOrganizacao] (
    [cnpjOrg] int  NOT NULL,
    [nomeOrg] nvarchar(4000)  NOT NULL,
    [telOrg] nvarchar(4000)  NOT NULL,
    [inscEstOrg] int  NOT NULL,
    [idOrg] int  NOT NULL
);
GO

-- Creating table 'enderecoSets'
CREATE TABLE [dbo].[enderecoSets] (
    [idEndereco] int IDENTITY(1,1) NOT NULL,
    [rua] nvarchar(4000)  NOT NULL,
    [bairro] nvarchar(4000)  NOT NULL,
    [numero] nvarchar(4000)  NOT NULL,
    [cidade] nvarchar(4000)  NOT NULL,
    [cep] nvarchar(4000)  NOT NULL,
    [estado] nvarchar(4000)  NOT NULL,
    [idUsuOrganizacao_idOrg] int  NOT NULL
);
GO

-- Creating table 'pagamentoSets'
CREATE TABLE [dbo].[pagamentoSets] (
    [idPagamento] int IDENTITY(1,1) NOT NULL,
    [formaPag] nvarchar(max)  NOT NULL,
    [resolProblema_idResolvProb] int  NOT NULL,
    [usuOrganizacao_idOrg] int  NOT NULL,
    [usuResolvedorSets_idUsuRes] int  NOT NULL,
    [premio_idPremio] int  NOT NULL
);
GO

-- Creating table 'premioSet_problemas'
CREATE TABLE [dbo].[premioSet_problemas] (
    [idProb] int IDENTITY(1,1) NOT NULL,
    [descProb] nvarchar(4000)  NOT NULL,
    [tituloProb] nvarchar(4000)  NOT NULL,
    [statusProb] nvarchar(4000)  NOT NULL,
    [dtInicioProb] nvarchar(4000)  NOT NULL,
    [dtFimProb] nvarchar(4000)  NOT NULL,
    [midiasProb] nvarchar(4000)  NOT NULL,
    [regraProb] nvarchar(4000)  NOT NULL,
    [idProblema] int  NOT NULL,
    [usuOrganizacao_idEndereco] int  NOT NULL,
    [idUsuOrganizacao_idOrg] int  NOT NULL
);
GO

-- Creating table 'premioSets'
CREATE TABLE [dbo].[premioSets] (
    [idPremio] int IDENTITY(1,1) NOT NULL,
    [vlPremio] nvarchar(4000)  NOT NULL,
    [tpPremio] nvarchar(4000)  NULL,
    [problema_idProblema] int  NOT NULL
);
GO

-- Creating table 'resolProblemaSets'
CREATE TABLE [dbo].[resolProblemaSets] (
    [idResolvProb] int IDENTITY(1,1) NOT NULL,
    [descProblema] nvarchar(4000)  NOT NULL,
    [dtIncioResol] datetime  NOT NULL,
    [dtFimResol] datetime  NOT NULL,
    [idProb_Id] int  NOT NULL,
    [idUsuRes_idUsuRes] int  NOT NULL,
    [idUsuRes_emailUsuRes] nvarchar(4000)  NOT NULL
);
GO

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- Creating table 'usuAdminsitradorSets'
CREATE TABLE [dbo].[usuAdminsitradorSets] (
    [idUsuAdm] int IDENTITY(1,1) NOT NULL,
    [nomUsuAdm] nvarchar(4000)  NOT NULL,
    [emailUsuAdm] nvarchar(4000)  NOT NULL,
    [senhaUsuAdm] nvarchar(4000)  NOT NULL
);
GO

-- Creating table 'usuResolvedorSets'
CREATE TABLE [dbo].[usuResolvedorSets] (
    [idUsuRes] int IDENTITY(1,1) NOT NULL,
    [emailUsuRes] nvarchar(4000)  NOT NULL,
    [nomeUsuRe] nvarchar(4000)  NOT NULL,
    [senhaUsuRes] int  NOT NULL,
    [sobrenomeUsu] nvarchar(max)  NOT NULL,
    [telResid] nvarchar(max)  NOT NULL,
    [telCel] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [idOrg] in table 'enderecoSet_usuOrganizacao'
ALTER TABLE [dbo].[enderecoSet_usuOrganizacao]
ADD CONSTRAINT [PK_enderecoSet_usuOrganizacao]
    PRIMARY KEY CLUSTERED ([idOrg] ASC);
GO

-- Creating primary key on [idEndereco] in table 'enderecoSets'
ALTER TABLE [dbo].[enderecoSets]
ADD CONSTRAINT [PK_enderecoSets]
    PRIMARY KEY CLUSTERED ([idEndereco] ASC);
GO

-- Creating primary key on [idPagamento] in table 'pagamentoSets'
ALTER TABLE [dbo].[pagamentoSets]
ADD CONSTRAINT [PK_pagamentoSets]
    PRIMARY KEY CLUSTERED ([idPagamento] ASC);
GO

-- Creating primary key on [idProblema] in table 'premioSet_problemas'
ALTER TABLE [dbo].[premioSet_problemas]
ADD CONSTRAINT [PK_premioSet_problemas]
    PRIMARY KEY CLUSTERED ([idProblema] ASC);
GO

-- Creating primary key on [idPremio] in table 'premioSets'
ALTER TABLE [dbo].[premioSets]
ADD CONSTRAINT [PK_premioSets]
    PRIMARY KEY CLUSTERED ([idPremio] ASC);
GO

-- Creating primary key on [idResolvProb] in table 'resolProblemaSets'
ALTER TABLE [dbo].[resolProblemaSets]
ADD CONSTRAINT [PK_resolProblemaSets]
    PRIMARY KEY CLUSTERED ([idResolvProb] ASC);
GO

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- Creating primary key on [idUsuAdm] in table 'usuAdminsitradorSets'
ALTER TABLE [dbo].[usuAdminsitradorSets]
ADD CONSTRAINT [PK_usuAdminsitradorSets]
    PRIMARY KEY CLUSTERED ([idUsuAdm] ASC);
GO

-- Creating primary key on [idUsuRes] in table 'usuResolvedorSets'
ALTER TABLE [dbo].[usuResolvedorSets]
ADD CONSTRAINT [PK_usuResolvedorSets]
    PRIMARY KEY CLUSTERED ([idUsuRes] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [idUsuOrganizacao_idOrg] in table 'enderecoSets'
ALTER TABLE [dbo].[enderecoSets]
ADD CONSTRAINT [FK_usuOrganizacaoendereco]
    FOREIGN KEY ([idUsuOrganizacao_idOrg])
    REFERENCES [dbo].[enderecoSet_usuOrganizacao]
        ([idOrg])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_usuOrganizacaoendereco'
CREATE INDEX [IX_FK_usuOrganizacaoendereco]
ON [dbo].[enderecoSets]
    ([idUsuOrganizacao_idOrg]);
GO

-- Creating foreign key on [usuOrganizacao_idOrg] in table 'pagamentoSets'
ALTER TABLE [dbo].[pagamentoSets]
ADD CONSTRAINT [FK_usuOrganizacaopagamento]
    FOREIGN KEY ([usuOrganizacao_idOrg])
    REFERENCES [dbo].[enderecoSet_usuOrganizacao]
        ([idOrg])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_usuOrganizacaopagamento'
CREATE INDEX [IX_FK_usuOrganizacaopagamento]
ON [dbo].[pagamentoSets]
    ([usuOrganizacao_idOrg]);
GO

-- Creating foreign key on [idUsuOrganizacao_idOrg] in table 'premioSet_problemas'
ALTER TABLE [dbo].[premioSet_problemas]
ADD CONSTRAINT [FK_usuOrganizacaoproblema]
    FOREIGN KEY ([idUsuOrganizacao_idOrg])
    REFERENCES [dbo].[enderecoSet_usuOrganizacao]
        ([idOrg])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_usuOrganizacaoproblema'
CREATE INDEX [IX_FK_usuOrganizacaoproblema]
ON [dbo].[premioSet_problemas]
    ([idUsuOrganizacao_idOrg]);
GO

-- Creating foreign key on [premio_idPremio] in table 'pagamentoSets'
ALTER TABLE [dbo].[pagamentoSets]
ADD CONSTRAINT [FK_premiopagamento]
    FOREIGN KEY ([premio_idPremio])
    REFERENCES [dbo].[premioSets]
        ([idPremio])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_premiopagamento'
CREATE INDEX [IX_FK_premiopagamento]
ON [dbo].[pagamentoSets]
    ([premio_idPremio]);
GO

-- Creating foreign key on [resolProblema_idResolvProb] in table 'pagamentoSets'
ALTER TABLE [dbo].[pagamentoSets]
ADD CONSTRAINT [FK_resolProblemapagamento]
    FOREIGN KEY ([resolProblema_idResolvProb])
    REFERENCES [dbo].[resolProblemaSets]
        ([idResolvProb])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_resolProblemapagamento'
CREATE INDEX [IX_FK_resolProblemapagamento]
ON [dbo].[pagamentoSets]
    ([resolProblema_idResolvProb]);
GO

-- Creating foreign key on [usuResolvedorSets_idUsuRes] in table 'pagamentoSets'
ALTER TABLE [dbo].[pagamentoSets]
ADD CONSTRAINT [FK_usuResolvedorSetspagamento]
    FOREIGN KEY ([usuResolvedorSets_idUsuRes])
    REFERENCES [dbo].[usuResolvedorSets]
        ([idUsuRes])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_usuResolvedorSetspagamento'
CREATE INDEX [IX_FK_usuResolvedorSetspagamento]
ON [dbo].[pagamentoSets]
    ([usuResolvedorSets_idUsuRes]);
GO

-- Creating foreign key on [problema_idProblema] in table 'premioSets'
ALTER TABLE [dbo].[premioSets]
ADD CONSTRAINT [FK_problemapremio]
    FOREIGN KEY ([problema_idProblema])
    REFERENCES [dbo].[premioSet_problemas]
        ([idProblema])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_problemapremio'
CREATE INDEX [IX_FK_problemapremio]
ON [dbo].[premioSets]
    ([problema_idProblema]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------